import { computed, ref } from 'vue'
import { dictDataApi } from '@/service/common.js'

/**
 * 字典
 */

const useDict = () => {
  const dictData = ref({})

  // 获取字典数据数组
  const getDictData = async (dictType) => {
    await dictDataApi({ dictType }).then(({ data }) => {
      dictData.value[dictType] = data
    })
  }

  // 显示字典label
  const getDictLabel = (key, val) => {
    return dictData.value[key]?.find((item) => item.dictValue === val)?.dictLabel
  }

  return {
    dictData,
    getDictData,
    getDictLabel
  }
}

export default useDict
